package com.labofjet.util;

import java.util.Locale;

import org.springframework.context.support.AbstractMessageSource;

public class MessageUtils {
	private static final AbstractMessageSource SOURCE = SpringContextUtils.getBean(AbstractMessageSource.class);

	private MessageUtils() {

	}

	/**
	 * 通过代码获取message
	 * 
	 * @param code
	 * @return
	 */
	public static String getMessage(String code) {
		return SOURCE.getMessage(code, null, null);
	}

	/**
	 * 通过代码获取message,带参数
	 * 
	 * @param code
	 * @param param
	 * @return
	 */
	public static String getMessage(String code, Object[] param) {
		return SOURCE.getMessage(code, param, null, null);
	}

	/**
	 * 通过代码获取message,没有就用默认的message
	 * 
	 * @param code
	 * @param defaultMessage
	 * @return
	 */
	public static String getMessage(String code, String defaultMessage) {
		return SOURCE.getMessage(code, null, defaultMessage, null);
	}

	/**
	 * 通过代码获取message,没有就用默认的message,带参数
	 * 
	 * @param code
	 * @param param
	 * @param defaultMessage
	 * @return
	 */
	public static String getMessage(String code, String defaultMessage, Object[] param) {
		return SOURCE.getMessage(code, param, defaultMessage, null);
	}

	public static String getMessage(String code, Object[] param, Locale locale) {
		return SOURCE.getMessage(code, param, locale);
	}

	public static String getMessage(String code, Object[] param, String defaultMessage, Locale locale) {
		return SOURCE.getMessage(code, param, defaultMessage, locale);
	}

}
